package com.gbb.simple.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Canvas之Path
 *
 * @author gaobingbing on 2017/5/23.
 */
public class PathDemoView extends View{

    private Paint mPathPaint;
    private Path mPath1;
    private Path mPath2;

    public PathDemoView(Context context){
        this(context,null);
    }

    public PathDemoView(Context context,@Nullable AttributeSet attrs){
        this(context,attrs,0);
    }

    public PathDemoView(Context context,@Nullable AttributeSet attrs,int defStyleAttr){
        super(context,attrs,defStyleAttr);
        init();
    }

    private void init(){
        mPathPaint = new Paint();
        mPathPaint.setAntiAlias(true);
        mPathPaint.setStrokeWidth(5);
        mPathPaint.setStyle(Paint.Style.FILL);

        mPath1 = new Path();
        mPath2 = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas){
        mPathPaint.setColor(Color.RED);
        mPath1.addCircle(200,200,100,Path.Direction.CW);
        mPath1.addOval(new RectF(300,300,500,500),Path.Direction.CW);
        canvas.drawPath(mPath1,mPathPaint);

        mPath2.addRect(250,250,400,400,Path.Direction.CW);
        mPathPaint.setColor(Color.BLUE);
        canvas.drawPath(mPath2,mPathPaint);
    }
}
